<?php
function edits( )
{
				global $db;
				$db->query( "select * from tun2_email WHERE id=".$_GET['id'] );
				if ( $db->next_record( ) )
				{
								echo "<script language=\"javascript\" src=\"inc/js.js\"></script>\r\n<table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\">\r\n <form action=\"Admin_Email.php?Action=edit\" method=\"post\" name=\"form\" onSubmit=\"return Validator.Validate(this,3)\">\r\n <input name=\"id\" type=\"hidden\" value=\"";
								echo $db->Record['id'];
								echo "\" /><input name=\"ip\" type=\"hidden\" value=\"";
								echo $db->Record['ip'];
								echo "\" />\r\n <tr>\r\n    <td width=\"15%\" align=\"right\">添加所用IP：</td>\r\n    <td>";
								echo $db->Record['ip'];
								echo "</td> <tr>\r\n    <td width=\"15%\" align=\"right\">邮箱地址：</td>\r\n    <td>\r\n  <input name=\"email\"  value=\"";
								echo $db->Record['email'];
								echo "\" size=\"50\" /></td>\r\n  </tr>\r\n  <tr>\r\n    <td align=\"right\">审核：</td>\r\n    <td><span style=\"float:left; width:260px;\">\r\n    <input name=\"verify\" type=\"checkbox\" value=\"1\" ";
								if ( $db->Record['verify'] ? 1 : 0 )
								{
												echo "checked";
								}
								echo " />\r\n \r\n </span></td>\r\n  </tr>\r\n  \r\n  <tr>\r\n    <td colspan=\"2\" align=\"center\"><input name=\"url\" type=\"hidden\" value=\"";
								echo $_SERVER['HTTP_REFERER'];
								echo "\"><input type=\"submit\" name=\"Submit_edit\" value=\"修改\" id=\"Submit_edit\" /></td>\r\n  </tr>\r\n </form>\r\n</table>\r\n<br>\r\n";
				}
}
function editall( )
{
				echo "<table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\">\r\n <form action=\"Admin_Email.php?Action=alledit\" method=\"post\" name=\"form\">\r\n <input name=\"id\" type=\"hidden\" value=\"";
				echo implode( ",", $_POST['id'] );
				echo "\" />\r\n     <td width=\"20%\" align=\"right\">审核：</td>\r\n    <td> <input name=\"verify\" value=\"1\" type=\"checkbox\" />\r\n</td> \r\n  </tr>\r\n    <tr>\r\n    <td colspan=\"2\" align=\"center\"><input name=\"url\" type=\"hidden\" value=\"";
				echo $_SERVER['HTTP_REFERER'];
				echo "\"><input type=\"submit\" name=\"submita\" value=\"确认\" /></td>\r\n  </tr>\r\n  </form>\r\n</table>\r\n";
}

include( "inc/header.php" );
login_check( );
echo "\r\n<body>\r\n";
switch ( $_REQUEST['Action'] )
{
case "add" :
				if ( function_exists( "date_default_timezone_set" ) )
				{
								date_default_timezone_set( "Hongkong" );
				}
				$addtime = date( "Y-m-d H-i-s" );
				$ip=getenv('REMOTE_ADDR');
				extract( $_POST );
				$pre = '/^([a-z0-9]*[-_\.]?[a-z0-9]+)+@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?/i'; //邮箱正则表达式
				if (isset($_POST['email']) && !empty($_POST['email']) && preg_match($pre,$_POST['email'])) {
					$resultc = mysql_query("SELECT email FROM tun2_email WHERE email='{$_POST['email']}'");
					if(mysql_num_rows($resultc)>0) {
						admin_showerr( "<li>该邮箱地址已经存在</li>", "Admin_Email.php", 0 );
					}
					else {
						$db->query( "INSERT INTO tun2_email (email,ip,verify,time) VALUES ('".$_POST['email']."','{$ip}','{$_POST['verify']}','{$addtime}')" );
						addlog( "添加邮箱", $_SESSION['user_name'] );
						admin_showerr( "<li>添加邮箱成功</li>", "Admin_Email.php", 1 );
					}
				}
				else {
					admin_showerr( "<li>请填写正确的邮箱地址</li>", "Admin_Email.php", 0 );
				}
				break;
case "edits" :
				edits( );
				break;
case "editall" :
				editall( );
				break;
case "edit" :
				if ( function_exists( "date_default_timezone_set" ) )
				{
								date_default_timezone_set( "Hongkong" );
				}
				$addtime = date( "Y-m-d H-i-s" );
				extract( $_POST );
				@$verify = @intval( $verify );
				$db->query( "UPDATE tun2_email SET email='".$_POST['email']."',\r\n\t\tip='{$_POST['ip']}',\r\n\t\tverify ={$verify },\r\n\t\ttime='{$addtime}' WHERE id={$_POST['id']}" );
				addlog( "修改<<".$_POST['id'].">>邮箱地址", $_SESSION['user_name'] );
				admin_showerr( "<li>修改邮箱成功</li>", $_POST['url'], 1 );
				break;

case "alledit" :
				extract( $_POST );
				@$verify = @intval( $verify );
				//$verify = @intval( $_POST['verify'] );
				$strSql = "UPDATE tun2_email SET ";
				
				if ( $verify )
				{
					$strSql .= "verify=".$verify.",";
				}
				else {
					$strSql .= "verify=0,";
				}
				
				$strSql = substr( $strSql, 0, -1 );
				$strSql .= " WHERE id IN (".$_POST['id'].")";
				$db1->query( $strSql );
				addlog( "批量审核邮箱", $_SESSION['user_name'] );
				admin_showerr( "<li>操作成功</li>", $_POST['url'], 1 );
				break;
case "del" :
				if ( isset( $_POST['id'] ) )
				{
								$chid = implode( ",", $_POST['id'] );
				}
				else
				{
								$chid = $_GET['id'];
				}

				$db->query( "DELETE FROM tun2_email WHERE id IN (".$chid.")" );
				addlog( "删除邮箱", $_SESSION['user_name'] );
				admin_showerr( "<li>删除邮箱成功</li>", $_SERVER['HTTP_REFERER'], 1 );
				break;
case "rec" :
case "verify" :
				$db->query( "UPDATE tun2_email set ".$_GET['Action']."={$_GET['value']} WHERE id={$_GET['id']}" );
				addlog( "修改邮箱属性", $_SESSION['user_name'] );
				header( "Location:".$_SERVER['HTTP_REFERER'] );
				break;
default :
				@$intPerpage = 20;
				if ( $_GET['PB_page'] )
				{
								$offset = ( $_GET['PB_page'] - 1 ) * $intPerpage;
				}
				else
				{
								$offset = 0;
				}
				if ( $_GET['keyword'] != "" )
				{
								$strSql = "SELECT * FROM tun2_email WHERE email like '%".trim( $_GET['keyword'] )."%'";
								$execc = "SELECT id FROM tun2_email WHERE email like '%".trim( $_GET['keyword'] )."%'";
				}
				/*else if ( $_GET['Action'] == "columns" )
				{
								$strSql = "SELECT * FROM tun2_email WHERE columnsname =".$_GET['columnsname'];
								$execc = "SELECT id FROM tun2_email WHERE columnsname =".$_GET['columnsname'];
				}*/
				else
				{
								$strSql = "SELECT * FROM tun2_email";
								$execc = "SELECT id FROM tun2_email";
				}
				if ( isset( $_GET['Attribute'] ) )
				{
								$strSql .= " where ".$_GET['Attribute']."=1";
								$execc .= " where ".$_GET['Attribute']."=1";
				}
				if ( empty( $_GET['Sorting'] ) )
				{
								$strSql .= " Order by id desc limit ".$offset.",{$intPerpage}";
				}
				else
				{
								$strSql .= " Order by ".$_GET['Sorting']." desc limit {$offset},{$intPerpage}";
				}
				$resultc = mysql_query( $execc );
				$intNum = mysql_num_rows( $resultc );
				$db->query( $strSql );
				echo "<table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\">\r\n <tr width=\"10%\" >\r\n<form action=\"Admin_Email.php?Action=add\" method=\"post\" name=\"form\"> \r\n   <td align=\"right\" width=\"10%\"> \r\n<strong>添加邮箱</strong>：</td>\r\n   <td><input name=\"email\" type=\"text\" style=\"width: 200px\" />\r\n   <input name=\"verify\" type=\"hidden\" value=\"1\" /> <input name=\"Submit\" type=\"submit\" id=\"Submit\" value=\"添加\"></td>\r\n</form>\r\n </tr></table><br/><table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\">\r\n <tr width=\"10%\" >\r\n<form action=\"Admin_Email.php\" method=\"get\"> \r\n   <td align=\"right\" width=\"10%\"> \r\n<strong>邮箱搜索</strong>：</td>\r\n   <td width=\"44%\"><input name=\"keyword\" type=\"text\" style=\"width: 200px\" />\r\n     <input name=\"Submit\" type=\"submit\" id=\"Submit\" value=\"开始搜索\"></td>\r\n</form>\r\n   <td><strong>查看方式</strong>:       \r\n     <a href=\"Admin_Email.php?Sorting=id\">邮箱ID</a> |  \r\n     <a href=\"Admin_Email.php?Sorting=verify\">审核</a>\r\n       </td>\r\n  </tr>\r\n</table>\r\n<br />\r\n<table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\">\r\n<form  name=\"forms\" action=\"Admin_Email.php\" method=\"post\">\r\n  <tr>\r\n    <td width=\"3%\">&nbsp;</td>\r\n    <td width=\"5%\" align=\"center\"><strong>ID</strong></td>\r\n    <td align=\"center\"><strong>邮箱地址</strong></td>\r\n   \r\n   <td width=\"5%\" align=\"center\"><strong>审核</strong></td>\r\n    <td width=\"20%\" align=\"center\"><strong>添加所用IP</strong></td>\r\n        <td width=\"12%\" align=\"center\"><strong>操作</strong></td>\r\n  </tr>\r\n";
				while ( $db->next_record( ) )
				{
								echo "  <tr onmouseover=\"this.bgColor='#D3EDFC'\" onmouseout=\"this.bgColor='#eff7fd'\">\r\n    <td><input name=\"id[]\" type=\"checkbox\" id=\"id\" value=\"";
								echo $db->Record['id'];
								echo "\" /></td>\r\n    <td align=\"center\">";
								echo $db->Record['id'];
								echo "</td>\r\n    <td>";
								echo $db->Record['email'];
								echo "</td>\r\n     <td  align=\"center\">\r\n\t";
								if ( $db->Record['verify'] == 0 )
								{
												echo "<a href=\"Admin_Email.php?Action=verify&id=".$db->Record['id']."&value=1\"><img src=\"images/icon_02.gif\" border=\"0\" /></a>";
								}
								else
								{
												echo "<a href=\"Admin_Email.php?Action=verify&id=".$db->Record['id']."&value=0\"><img src=\"images/icon_01.gif\" border=\"0\" /></a>";
								}
								echo "</td>\r\n   <td align=\"center\">";
								echo $db->Record['ip'];
								echo "</td> <td align=\"center\"><a href=\"Admin_Email.php?Action=edits&id=";
								echo $db->Record['id'];
								echo "\">修改</a> ｜ <a href=\"Admin_Email.php?Action=del&id=";
								echo $db->Record['id'];
								echo "\">删除</a></td>\r\n  </tr>\r\n";
				}
				echo "  <tr>\r\n    <td><input name=\"chkall\" type=\"checkbox\" id=\"chkall\" value=\"checkbox\" onClick=\"CheckAll(document.forms.chkall.checked);\"/></td>\r\n    <td colspan=\"8\"><input name=\"Action\" type=\"hidden\" value=\"\">\r\n\t  <input type=\"button\" name=\"del\" value=\"批量删除\"  onClick=\"document.forms.Action.value='del';{if(chkCheckBoxChs('id')==false){alert('请至少选择一个邮箱！');return;}};{if(confirm('确定删除您所选择的邮箱吗？')){this.document.forms.submit();return true;}}\">\r\n      <input type=\"button\" name=\"editall\" value=\"批量审核所选邮箱\" onClick=\"document.forms.Action.value='editall';{if(chkCheckBoxChs('id')==false){alert('请至少选择一个邮箱！');return;}};this.document.forms.submit();\"></td>\r\n  </tr>\r\n</form>\r\n  <tr>\r\n    <td colspan=\"9\">";
				require_once( "../inc/class.page.php" );
				class mypage extends page
				{

								public function show( )
								{
												$_showpage = "<div class=\"pagenavi\" id=\"lopage\">";
												$_showpage .= $this->first_page( )." ";
												$_showpage .= $this->nowbar( "", "curr" );
												$_showpage .= "<span class=\"break\">...</span>";
												$_showpage .= $this->last_page( );
												$_showpage .= "   (总计<span class=\"num\">".$this->totalpage."</span>页 <span class=\"num\">".$this->total."</span>条记录)</div>";
												$_showpage .= "</div>";
												return $_showpage;
								}

				}

				$page = new mypage( array(
								"total" => $intNum,
								"perpage" => $intPerpage
				) );
				echo $page->show( );
}
echo "</td>\r\n  </tr>\r\n</table>\r\n<script language=\"javascript\">\r\nfunction CheckAll(v)\r\n\t{\r\n\t\tvar i;\r\n\t\tfor (i=0;i<document.forms.elements.length;i++)\r\n\t\t{\r\n\t\t\tvar e = document.forms.elements[i];\r\n\t\t        e.checked = v;\r\n\t\t}\r\n}\r\n\r\nfunction setid(number,url,format,datalist)\r\n{\r\nvar str='';\r\nif(!document.getElementById(number).value)\r\ndocument.getElementById(number).value=1;\r\nfor(i=1;i<=document.getElementById(number).value;i++)\r\n{\r\nif (str!=\"\")\r\n{\r\nstr+='\\r';\r\n}\r\nif(document.getElementById(number).value<10)\r\n{\r\nstr+=document.getElementById(url).value+'0'+i+''+document.getElementById(format).value;\r\n}  \r\nelse if(document.getElementById(number).value<100)\r\n{\r\n\tif(i<10)\r\n\t{\r\n\tstr+=document.getElementById(url).value+''+'0'+i+''+document.getElementById(format).value;\r\n\t}\r\n\telse\r\n\t{\r\n\tstr+=document.getElementById(url).value+''+i+''+document.getElementById(format).value;\r\n\t}\r\n} \r\nelse if(document.getElementById(number).value<1000)\r\n{\r\n\tif(i<10)\r\n\t{\r\n\tstr+=document.getElementById(url).value+''+'00'+i+''+document.getElementById(format).value;\r\n \t} \r\nelse if(i<100)\r\n\t{\r\n\tstr+=document.getElementById(url).value+''+'0'+i+''+document.getElementById(format).value;\r\n \t}\r\n\telse\r\n\t{\r\n\tstr+=document.getElementById(url).value+''+i+''+document.getElementById(format).value;\r\n\t}\r\n}\r\n}\r\ndocument.getElementById(datalist).value=''+str+'';\r\n}\r\n\r\nfunction showcheckbox(cname,dname)\r\n{\r\nif(document.getElementById(cname).checked==true)\r\n{\r\nshowThumbnail_RateOrSize(1,dname)\r\n}\r\nelse\r\n{\r\nshowThumbnail_RateOrSize(0,dname)\r\n}\r\n}\r\n";

echo "function showThumbnail_RateOrSize(param,pname)\r\n{\r\n\tif(param==1)\r\n\t{\r\n\t\tdocument.getElementById(pname).style.display=\"block\";\r\n\t}else\r\n\t{\r\n\t\tdocument.getElementById(pname).style.display=\"none\";\r\n\t}\r\n}\r\n\r\nfunction chkCheckBoxChs(objNam){\r\nvar obj = document.getElementsByName(objNam);\r\nvar objLen= obj.length;\r\nvar objYN;\r\nvar i;\r\nobjYN=false;\r\nfor (i = 0;i< objLen;i++){\r\nif (obj [i].checked==true) {\r\nobjYN= true;\r\nbreak;\r\n}\r\n}\r\nreturn objYN;\r\n}\r\n  </script>\r\n</body>\r\n</html>";
?>
